﻿/// <reference path="../GeneratedArtifacts/viewModel.js" />

myapp.ViewAnimal.created = function (screen) {
    // Write code here.
    screen.getCanUpdateAnimal().then(function success() {
        screen.findContentItem("EditAnimal").isEnabled = true;
        screen.findContentItem("AddVaccine").isEnabled = true;
        screen.findContentItem("AddMovement").isEnabled = true;
        screen.findContentItem("AddMedia").isEnabled = true;
    }, function error() {
        screen.findContentItem("EditAnimal").isEnabled = false;
        screen.findContentItem("AddVaccine").isEnabled = false;
        screen.findContentItem("AddMovement").isEnabled = false;
        screen.findContentItem("AddMedia").isEnabled = false;
    });

    screen.getEmails().then(function success() {
        screen.findContentItem("EmailAnimal").isEnabled = true;
    }, function error() {
        screen.findContentItem("EmailAnimal").isEnabled = false;
    });

    //screen.getCanUpdateAnimal.then(screen.findContentItem("EditAnimal").isEnabled = true, screen.findContentItem("EditAnimal").isEnabled = false);

};
myapp.ViewAnimal.Refresh_execute = function (screen) {
    // Write code here.
    //window.location.reload();
    //window.location = window.location.pathname;
    //location.reload()
    //history.go(0)
    //location.href = location.href
    //location.href = location.pathname;
    //location.replace(location.pathname)
    //location.reload(false)
    location.reload()
};
myapp.ViewAnimal.Photo1_Tap_execute = function (screen) {
    // Write code here.
    screen.closePopup();
};
myapp.ViewAnimal.EmailAnimal_Tap_execute = function (screen) {
    // Write code here.
    myapp.showAddEditEmail(null, {
        beforeShown: function (addNewScreen) {
            var cur_animal = screen.Animal;
            var new_email = new myapp.Email();
            new_email.FromEmailAddress = "themuttscouts@gmail.com";
            new_email.IsHTML = false;
            new_email.IncludeMedia = false;
            new_email.Animal = cur_animal;
            addNewScreen.Email = new_email;
        }
    })
};